package member.member.action;

import m.common.action.ActionRequest;
import m.common.action.Param;
import m.common.action.RequestMethod;
import m.common.model.util.ModelQueryList;
import m.common.model.util.QueryCondition;
import m.common.model.util.QueryOrder;
import m.system.exception.MException;
import m.system.util.JSONMessage;
import member.order.model.OrderDetail;
import member.order.model.OrderInfo;
import member.order.model.OrderPay;

@ActionRequest(name = "action/member/orderInfo",description = "订单")
public class OrderInfoAction extends MemberAction{
    @RequestMethod(description = "我的列表")
    public JSONMessage getMyList() throws Exception {
        ModelQueryList queryList=toQueryList(OrderInfo.class,"*","inputStore.*","serveUser.realName");
        queryList.addCondition(QueryCondition.eq("member.oid", getSessionOid()));
        return JSONMessage.success("查询成功").push("page", ModelQueryList.getModelPageInfo(queryList));
    }
    @RequestMethod(description = "获取信息")
    public JSONMessage getInfo(@Param("oid") String oid) throws Exception {
        OrderInfo model=ModelQueryList.getModel(OrderInfo.class,oid,"*","member.*","member.level.*",
            "inputUser.realName","inputUser.phoneNum","serveUser.realName","serveUser.phoneNum","confirmUser.realName","confirmUser.phoneNum");
        if(null==model) throw new MException("订单信息不存在");
        verifyMember(model.getMember());
        return JSONMessage.success("查询成功")
            .push("model",model)
            .push("list",
                ModelQueryList.getModelList(OrderDetail.class,new String[]{"*","serve.*","serve.type.*"},null,
                    QueryCondition.eq("order.oid",oid), QueryOrder.asc("oid"))
            )
            .push("pays",
                ModelQueryList.getModelList(OrderPay.class,new String[]{"*"},null,
                    QueryCondition.eq("order.oid",oid),QueryOrder.asc("oid"))
            );
    }
}
